3<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>模板指标管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var tmplId='${tmplId}';
	var grid = null;
	var yesOrNoCdListJSON = [];
	var detailFlag='${detailFlag}';
    <c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>
	$(function () {
		initGrid();//grid
		if(detailFlag=="true"){
			$("#addBtn").hide();
			$("#removeBtn").hide();
		}
	});
	
	//初始化列表
	function initGrid(){
		var params = {};
		params.tmplId = tmplId;
		$("#grid").ligerGrid({
	    	url: '<%=path%>/system/sysscoretmpl/initIdxList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	          { display: '指标编号', name: 'id', minWidth: 240,
	            	render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
	            		    h='<a class="sq-button-hasicon" href="javascript:detailBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">'+value+'</a>'
	                        return h;
	            		}	
	            },
	            { display: '指标名称', name: 'idxNm', minWidth: 150,enabledSort:true},
	            { display: '指标字段', name: 'idxCd', minWidth: 150 ,enabledSort:true},
	            { display: '指标系数', name: 'idxDesc', minWidth: 400,enabledSort:true},
	            {
	                display: '操作',
	                isSort: false,
	                width: 200,
	                render: function (rowdata, rowindex, value){
                	 var h="";
                
                        h='<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_4"></i>修改</a>'
                        h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_7"></i>删除</a>'
	               		
	                     /*    h+='<a class="sq-button-hasicon" href="javascript:detailBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">详细</a>' */
	                    return h;
	                }
	            }
	        ],
	        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
                if (e.selected && e.column.columnname == "isFormalPrpsNm") {
                    e.record.isFormalPrpsId = e.value;
                    e.value = e.selected[e.column.editor.textField];
                }
            },
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: true,
	        rownumbers:true,
	        enabledEdit: true,
	        usePagerOnLessPagesize: true,
	        onAfterEdit: f_onAfterEdit,
	    });
		grid = liger.get("grid");
		grid.setHeight(300);
		
		 //编辑后事件 
        function f_onAfterEdit(e)
        {
            if (e.column.name == "isFormalPrps")
            {
            //	var val = e.record.isFormalPrps;//获取值
            	//值为是默认方案
            		//判断grid中默认值的数量>1提示
            		 var grid = $("#grid").ligerGetGridManager();
                     var data = grid.getData();
                     var  num = 0;
            	// 	for(var i=0;i<data.length;i++){
            		//	if(data[i].isFormalPrps=="1"){
            		//		num+=1;
            		//	}
            	//	} 
             		//if(num==0){
				//		 top.$.ligerDialog.SQalert({content: "请设置一个默认的一个正式模板指标！",SQ_type: "error"});
				//		 return;
           		//	}
             		
            	/* 	if(num>1){
						 top.$.ligerDialog.SQalert({content: "该项目只能有一个正式模板指标！",SQ_type: "error"});
						 return;
            		}  */
            	//	if(num==1){
            		//	for(var i=0;i<data.length;i++){
                			//if(data[i].isFormalPrps=="1"){
                    				//修改方案为默认方案
             //       				var val = e.record.isFormalPrps;//获取值
             //       				var params = {};
             //       				params.tmplId = tmplId;
             //       				params.isFormalPrps = val;
             //       				params.id=e.record.id;
             //       				setIsFormalPrpsStatus(params);
                		//	}
                	//	}
            //		}
            	
            }
        } 
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
        var h="￥" + FormatMoney(value)
        return h;
    }


	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value&&value!=''){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//添加
	function addBtn(tmplId){
	//alert(tmplId)
		var callback = function(){
			 grid.reload();
		}
	Add_navTab('tab_idx'+tmplId,'新增模板指标','<%=path%>/system/sysscoretmpl/toIdxAddPage.do?tmplId='+tmplId,callback);
	}

	//修改
	function modifyBtn(idxId){
		var callback = function(){
			 grid.reload();
		}

		Add_navTab('tab_idx'+idxId,'修改模板指标','<%=path%>/system/sysscoretmpl/toIdxModifyPage.do?idxId='+idxId,callback);
	}
	
	//查看
	function detailBtn(idxId){
		var editFlag = true;
		Add_navTab('tab_idx'+idxId,'查看模板指标','<%=path%>/system/sysscoretmpl/toIdxModifyPage.do?detailFlag=1&idxId='+idxId);
	}
	//删除
	function deletBtn(idxId){
		var editFlag = true;
		Add_navTab('tab_idx'+id,'删除模板指标','<%=path%>/system/sysscoretmpl/removeIdxById.do?idxId='+idxId);
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//删除所选信息
	function removeBtn(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/system/sysscoretmpl/removeByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
	

	
	
	
	
	
	
</script>

<body class="iframeBody">
	<div class="Wrapper">
      <div id="pageInTab" class="pageInTab">
      <div class="searchArea">
    <form id="searchBar">
       <div class="fieldset1 clearFix">
<div class="btnsBox">
         <span id="addBtn"  onclick="addBtn('${tmplId}');"  class="sq-button sq-button-round" >新增</span>
         <span id="removeBtn" onclick="removeBtn();" class="sq-button sq-button-round">删除</span>

  </div>
  </div>
</form>
</div>
<div id="grid" class="sq-grid"></div>
</div>
		</div>
</body>
</html>